package 哈希表;

import java.util.HashMap;
import java.util.Map;

public class Demo06 {
    static class Solution {
        public boolean isHappy(int n) {
            Map<Integer,Integer> map = new HashMap<>();
            int next = n;
            while(true){
                int temp = next;
                int sum = 0;
                while(next>0){
                    sum += (next%10)*(next%10);
                    next = next/10;
                }

                if(sum == 1){
                    return true;
                }

                if(map.containsKey(sum)){
                    return false;
                }
                map.put(temp,sum);
                next = sum;
            }
        }
    }
}
